<?php

namespace App\Http\Controllers;

use App\User;
use App\Utils\Token;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    protected function getBusinessId()
    {

        if(Token::getUser()->type == 'admin'){
            $user = User::find(Token::getUser()->parent_id);
            return $user->business->id;
        }else{
            return Token::getUser()->business->id ?? null;
        }
    }


    protected function getTenantId()
    {
        return Token::getUser()->tenant->id ?? null;
    }

    protected function getUser()
    {
        return Token::getUser();
    }
}
